package com.kantboot.security.domain.entity;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.io.Serializable;
import java.util.Date;

/**
 * 关于网络请求的安全保障
 */
@Entity
@Getter
@Setter
@Table(name = "security_request")
@Accessors(chain = true)
@EntityListeners(AuditingEntityListener.class)
@DynamicUpdate
@DynamicInsert
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class SecurityRequest implements Serializable {

    /**
     * 主键
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 公钥
     */
    @Column(name = "public_key",length = 2000)
    private String publicKey;

    /**
     * 私钥
     */
    @Column(name = "private_key",length = 2000)
    private String privateKey;

    /**
     * 用户浏览器的UA
     * 用来做安全性校验，稍微防止伪造请求
     */
    @Column(name = "user_agent",length = 2000)
    private String userAgent;

    /**
     * 关联的token
     */
    @Column(name = "token",length = 2000)
    private String token;

    /**
     * 最后一次ip
     */
    @Column(name = "last_ip")
    private String lastIp;

    /**
     * ip数组字符串
     */
    @Column(name = "ip_list_str")
    private String ipListStr;

    /**
     * 过期时间
     */
    @Column(name = "gmt_expire")
    private Date gmtExpire;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "gmt_create")
    private Date gmtCreate;

    /**
     * 修改时间
     */
    @CreatedDate
    @Column(name = "gmt_modified")
    private Date gmtModified;

}
